#include "Main.h"
#include <iostream>
char gunther [3][3]={{' ',' ',' '},
					 {' ',' ',' '},
					 {' ',' ',' '},};
int h,w = 0;
bool winner = false;
Class1::Class1(void)
{

}
Class1::~Class1(void)
{
}
void PrintGrid (){
	for(h=0;h<3;h++){
		for(w=0;w<3;w++){
			if(w<1){
			cout<<"|"<<gunther[h][w]<<"|";
			}else{
			cout<<gunther[h][w]<<"|";
			}	
		}
		cout<<"\n";
	}
}
void Player1Mark(){
	int rd,cd = 0;
	bool Finn = true;
	while(Finn){
		cout<<"What row would player 1 like to mark? ";
		cin>>rd;
		cout<<"What column would player 1 like to mark? ";
		cin>>cd;
		if(rd<4&&cd<4&&gunther[rd-1][cd-1]==' '){
			gunther[rd-1][cd-1]='x';
			Finn=false;
		}else{
			cout <<"Please enter integers that are from 1-3, or please use a slot that is not already filled"<<"\n";
		}
	}
}
void Player2Mark (){
	int r,c = 0;
	bool Jake = true;
	while(Jake){
		cout<<"What row would player 2 like to mark? ";
		cin>>r;
		cout<<"What column would player 2 like to mark? ";
		cin>>c;
		if(r<4&&c<4&&gunther[r-1][c-1]==' '){
			gunther[r-1][c-1]='o';
			Jake=false;
		}else{
			cout <<"Please enter integers that are from 1-3, or please use a slot that is not already filled"<<"\n";
		}
	}
}
void CheckWinner(char lsp){
	int pb = lsp;
	if(gunther[0][0]==pb&&gunther[0][1]==pb&&gunther[0][2]==pb){
		if(pb=='x'){
			cout<<"Player 1 is the winner!";
			winner=true;
		}else{
			cout<<"Player 2 is the winner!";
			winner=true;
		}
	}
	if(gunther[1][0]==pb&&gunther[1][1]==pb&&gunther[1][2]==pb){
		if(pb=='x'){
			cout<<"Player 1 is the winner!";
			winner=true;
		}else{
			cout<<"Player 2 is the winner!";
			winner=true;
		}
	}
	if(gunther[2][0]==pb&&gunther[2][1]==pb&&gunther[2][2]==pb){
		if(pb=='x'){
			cout<<"Player 1 is the winner!";
			winner=true;
		}else{
			cout<<"Player 2 is the winner!";
			winner=true;
		}
	}
	if(gunther[0][0]==pb&&gunther[1][0]==pb&&gunther[2][0]==pb){
		if(pb=='x'){
			cout<<"Player 1 is the winner!";
			winner=true;
		}else{
			cout<<"Player 2 is the winner!";
			winner=true;
		}
	}
	if(gunther[0][1]==pb&&gunther[1][1]==pb&&gunther[2][1]==pb){
		if(pb=='x'){
			cout<<"Player 1 is the winner!";
			winner=true;
		}else{
			cout<<"Player 2 is the winner!";
			winner=true;
		}
	}
	if(gunther[0][2]==pb&&gunther[1][2]==pb&&gunther[2][2]==pb){
		if(pb=='x'){
			cout<<"Player 1 is the winner!";
			winner=true;
		}else{
			cout<<"Player 2 is the winner!";
			winner=true;
		}
	}
	if(gunther[0][0]==pb&&gunther[1][1]==pb&&gunther[2][2]==pb){
		if(pb=='x'){
			cout<<"Player 1 is the winner!";
			winner=true;
		}else{
			cout<<"Player 2 is the winner!";
			winner=true;
		}
	}
	if(gunther[0][2]==pb&&gunther[1][1]==pb&&gunther[2][0]==pb){
		if(pb=='x'){
			cout<<"Player 1 is the winner!";
			winner=true;
		}else{
			cout<<"Player 2 is the winner!";
			winner=true;
		}
	}
}
int main (void){
while(winner==false){
	PrintGrid();
	CheckWinner('x');
	CheckWinner('o');
	cout<<"Use 1-3 to choose rows and columns"<<"\n";
	Player1Mark();
	PrintGrid();
	CheckWinner('x');
	CheckWinner('o');
	cout<<"Use 1-3 to choose rows and columns"<<"\n";
	Player2Mark();
}
	cin.ignore();
	return 0;

}